﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Linq;
using System.Text;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class EDIT_TXTKON
    {
     
        public string UserID;
        public string UserGroup;
        public List<string> EditibleLine;
        public EDIT_TXTKON()
        {
            UserID = "";
            UserGroup = "";
            EditibleLine = new List<string>();
        }
    }
    public class VKPOSData : BaseFunction
    {
        public bool checkVK07 = true;
        public VKPOSData()
            : base()
        {

        }
        public VKPOSData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection,_proxy,userID)
        {
        }
        public VKPOSData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {

        }

        public DataSet GetVKKOPF(DataRow dwVKKOPF)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            string VKPAUFNUM;
            string VKKMANDANT, VKKAUFKRS, VKKAUFLFD;

            VKKMANDANT = dwVKKOPF["VKKMANDANT"].ToString().Trim();
            VKKAUFKRS = dwVKKOPF["VKKAUFKRS"].ToString().Trim();
            VKKAUFLFD = dwVKKOPF["VKKAUFLFD"].ToString().Trim();
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                /*
                SELECT VKKKUNDNR,KDKUNDNA,VKKVB,VKKORDER,VKKSACHBE,VKKBESTNR,VKKVERSART,VKKSPED  FROM VKKOPF K LEFT JOIN KDSTAMM ON VKKKUNDNR=KDKUNDNR AND VKKMANDANT=KDMANDANT WHERE VKKMANDANT='00' AND VKKAUFKRS='C0' AND VKKAUFLFD='100227' ORDER BY 1,2,3,4
                 */
                or1.CommandText = "SELECT VKKMANDANT,VKKAUFKRS,VKKAUFLFD,VKKKUNDNR,KDKUNDNA,VKKVB,VKKORDER,VKKSACHBE,VKKBESTNR,VKKVERSART,VKKSPED "
                    + " FROM VKKOPF K"
                    + " LEFT JOIN KDSTAMM ON VKKKUNDNR=KDKUNDNR AND VKKMANDANT=KDMANDANT "
                    + " WHERE VKKMANDANT=:VKKMANDANT AND VKKAUFKRS=:VKKAUFKRS AND VKKAUFLFD=:VKKAUFLFD AND VKKSA = '  ' "
                    //+" WHERE VKKMANDANT='00' AND VKKAUFKRS='C0' AND VKKAUFLFD='100227'" 
                    + " ORDER BY 1,2,3,4";

                or1.Parameters.Add("VKKMANDANT", OracleType.NVarChar).Value = dwVKKOPF["VKKMANDANT"].ToString();
                or1.Parameters.Add("VKKAUFKRS", OracleType.NVarChar).Value = dwVKKOPF["VKKAUFKRS"].ToString();
                or1.Parameters.Add("VKKAUFLFD", OracleType.NVarChar).Value = dwVKKOPF["VKKAUFLFD"].ToString();
                #endregion
                setLocal = Connect2Proxy(or1);

                if (setLocal.Tables.Count > 0)
                {
                    tableLocal = setLocal.Tables[0];
                    tableLocal.TableName = "VKKOPF";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    string KDKUNDNA;
                    bool found = false;
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        found = true;
                        Column = "KDKUNDNA";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                    }
                    if (!found)
                    {
                        MessageBox.Show("请输入正确的销售单号码");
                    }
                    set4Return.Merge(setLocal);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet GetVKPOS(DataRow dwVKKOPF)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                /* VKPAUFMART
VKPVERPART

                 */
                or1.CommandText = "SELECT VKPMANDANT,KDNAME1,VKKBESTNR,VKKBESTDAT,VKPAUFKRS,VKPAUFLFD,VKPAUFPOS"
                    + ",VKPSA,VKPEZEIT,VKPAENDBEN,VKPAUFMART,VKPVERPART"
                    + ",VKPAENDDAT,VKPNEUBEN,VKPNEUDAT,VKPPOSTYP,VKPARTST"
                    + ",VKPKOLL,VKPART,VKPFARBE,VKPKDFARBNR"
                + ",SUBSTR(M.SDDATEN,2,10) AS VKPVERPART,SUBSTR(P.SDDATEN,2,10) AS VKPVERPART"
                    + ",VKPKDARTNR,VKPKDBEZ,ROUND(VKPMENGE1*0.01,0) AS VKPMENGE1,VKPMEEH,VKPMEEHFKT"
                    + ",VKPMENGE1T1,VKPMENGE1T2,VKPLIEFTERM"
                    + ",0 AS KTXTIPIND,0 AS PTXTIPIND"
                    + ",'' as KVKTTXT01,'' as KVKTTXT02,'' as KVKTTXT03,'' as KVKTTXT04,'' as KVKTTXT05"
                       + ",'' as KVKTTXT06,'' as KVKTTXT07,'' as KVKTTXT08,'' as KVKTTXT09,'' as KVKTTXT10"
                       + ",'' as KVKTTXT11,'' as KVKTTXT12,'' as KVKTTXT13,'' as KVKTTXT14,'' as KVKTTXT15"
                       + ",'' as KVKTTXT16,'' as KVKTTXT17,'' as KVKTTXT18,'' as KVKTTXT19,'' as KVKTTXT20"
                                          + ",'' as KVKTTXT21,'' as KVKTTXT22,'' as KVKTTXT23,'' as KVKTTXT24,'' as KVKTTXT25"
                       + ",'' as KVKTTXT26,'' as KVKTTXT27,'' as KVKTTXT28,'' as KVKTTXT29,'' as KVKTTXT30"
                       + ",'' as KVKTTXT31,'' as KVKTTXT32,'' as KVKTTXT33,'' as KVKTTXT34,'' as KVKTTXT35"
                                + ",'' as PVKTTXT01,'' as PVKTTXT02,'' as PVKTTXT03,'' as PVKTTXT04,'' as PVKTTXT05"
                       + ",'' as PVKTTXT06,'' as PVKTTXT07,'' as PVKTTXT08,'' as PVKTTXT09,'' as PVKTTXT10"
                       + ",'' as PVKTTXT11,'' as PVKTTXT12,'' as PVKTTXT13,'' as PVKTTXT14,'' as PVKTTXT15"
                       + ",'' as PVKTTXT16,'' as PVKTTXT17,'' as PVKTTXT18,'' as PVKTTXT19,'' as PVKTTXT20"
                                          + ",'' as PVKTTXT21,'' as PVKTTXT22,'' as PVKTTXT23,'' as PVKTTXT24,'' as PVKTTXT25"
                       + ",'' as PVKTTXT26,'' as PVKTTXT27,'' as PVKTTXT28,'' as PVKTTXT29,'' as PVKTTXT30"
                       + ",'' as PVKTTXT31,'' as PVKTTXT32,'' as PVKTTXT33,'' as PVKTTXT34,'' as PVKTTXT35"
                    + " FROM VKPOS P JOIN VKKOPF ON   VKKMANDANT=VKPMANDANT AND VKKAUFKRS=VKPAUFKRS AND VKKAUFLFD=VKPAUFLFD"
                    + " LEFT JOIN KDSTAMM ON VKKKUNDNR=KDKUNDNR AND VKKMANDANT=KDMANDANT"
                    + " LEFT JOIN SDDAT M ON VKPMANDANT = SUBSTR(M.SDKEY,1,2)  AND VKPAUFMART = SUBSTR(M.SDKEY,3,3) AND M.SDSA = '0114' AND SUBSTR(M.SDKEY,24,1) = 'V'"
                    + "LEFT JOIN SDDAT P ON VKPMANDANT = SUBSTR(P.SDKEY,1,2)  AND VKPVERPART = SUBSTR(P.SDKEY,3,3) AND P.SDSA = '0209' AND SUBSTR(P.SDKEY,24,1) = 'V'"
                + " WHERE VKPMANDANT=:VKPMANDANT AND VKPSA='  ' AND VKKSA = '  ' AND VKPAUFKRS=:VKPAUFKRS AND VKPAUFLFD=:VKPAUFLFD";
                or1.Parameters.Add("VKPMANDANT", OracleType.NVarChar).Value = dwVKKOPF["VKKMANDANT"].ToString();
                or1.Parameters.Add("VKPAUFKRS", OracleType.NVarChar).Value = dwVKKOPF["VKKAUFKRS"].ToString();
                or1.Parameters.Add("VKPAUFLFD", OracleType.NVarChar).Value = dwVKKOPF["VKKAUFLFD"].ToString();

                #endregion
                setLocal = Connect2Proxy(or1);
                if (setLocal.Tables.Count > 0)
                {
                    tableLocal = setLocal.Tables[0];
                    tableLocal.TableName = "VKPOS";
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    string KDKUNDNA;
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {

                        Column = "VKPFARBE";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "KDNAME1";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "VKPKDFARBNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "VKPKDARTNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "VKPKDBEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        DataSet setTXTKOPF = GetVKTXT(dwTemp, "BEST", checkVK07);
                        foreach (DataRow dwTXT in setTXTKOPF.Tables["TXTIND"].Rows)
                        {
                            dwTemp["PTXTIPIND"] = dwTXT["TXTIPIND"];
                        }
                        foreach (DataRow dwTXT in setTXTKOPF.Tables["TXTKON"].Rows)
                        {
                            int TXTKPOS = System.Convert.ToInt32(dwTXT["TXTKPOS"].ToString().Trim()) / 10;
                            string pos = Right("0" + TXTKPOS.ToString(), 2);
                            string column = Left("PVKTTXT" + pos, 9);
                            dwTemp[column] = dwTXT["TXTKTEXT"];
                            dwTemp["PTXTIPIND"] = dwTXT["TXTIPIND"];
                        }
                    }

                    set4Return.Merge(setLocal);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet GetVKTXT(DataRow dwVKPOS, string type = "BEST", bool flagCreate = true)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            string KRS = dwVKPOS["VKPAUFKRS"].ToString().Trim();
            string LFD = dwVKPOS["VKPAUFLFD"].ToString().Trim();
            string POS = dwVKPOS["VKPAUFPOS"].ToString().Trim();
            string VKPAUF = KRS + LFD + POS;
            string TXTISIND = VKPAUF + type + "                                             ";
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();
                #region
                /* 
                 */
                or1.CommandText = "SELECT * FROM TXTIND "
                    + " WHERE TXTIMANDANT=:TXTIMANDANT AND TXTITXTART='VKT'"
                    + " AND TXTISIND = '" + TXTISIND + "'"
                    + "ORDER BY 1,2,3,4";
                or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"].ToString();
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count == 0)
                    return set4Return;
                tableLocal = setResult.Tables[0];
                tableLocal.TableName = "TXTIND";
                if (tableLocal.Rows.Count == 0)
                {
                    if (flagCreate)
                    {
                        setResult = InsertTXTIND(dwVKPOS);
                        set4Return.Merge(setResult);
                        return set4Return;
                    }
                }
                set4Return.Merge(setResult);
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT TXTISIND,TXTIPIND,TXTKPIND,TXTKPOS,TXTKTEXT"
                    + " FROM TXTIND T JOIN TXTKON ON TXTIMANDANT=TXTKMANDANT AND  TXTIPIND=TXTKPIND"
                    + " WHERE TXTIMANDANT=:TXTIMANDANT AND TXTITXTART='VKT'"
                    + " AND TXTISIND = '" + TXTISIND + "'"
                    + "ORDER BY 1,2,3,4";
                or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwVKPOS["VKPMANDANT"].ToString();
                setResult = Connect2Proxy(or1);
                tableLocal = setResult.Tables[0];
                tableLocal.TableName = "TXTKON";
                byte[] b;
                string value;
                string sTemp = "";
                string Column = "";
                string KDKUNDNA;
                foreach (DataRow dwTemp in tableLocal.Rows)
                {
                    Column = "TXTKTEXT";
                    #region
                    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                    value = Encoding.GetEncoding("gb2312").GetString(b);
                    if (value == "")
                    {
                        value = ".";
                    }
                    dwTemp[Column] = value;
                    #endregion
                }
                set4Return.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet InsertTXTIND(DataRow dwVKPOS, string type = "BEST")
        {
            DataSet setReturn = new DataSet();
            DataSet setResult;
            int TXTIPIND = 1;
            string KRS = dwVKPOS["VKPAUFKRS"].ToString().Trim();
            string LFD = dwVKPOS["VKPAUFLFD"].ToString().Trim();
            string POS = dwVKPOS["VKPAUFPOS"].ToString().Trim();
            string VKPAUF = KRS + LFD + POS;
            string TXTISIND = VKPAUF + type + "                                             ";
            string date = DateTime.Now.Year.ToString() + Right("00" + DateTime.Now.Month.ToString(), 2)
                + Right("00" + DateTime.Now.Day.ToString(), 2);
            OracleCommand or1 = OracleDB.CreateCommand();

            try
            {
                #region GetTXTISIND

                or1.CommandText = "SELECT MAX(TXTIPIND)  as TXTIPIND FROM TXTIND";
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    TXTIPIND = System.Convert.ToInt32(setResult.Tables[0].Rows[0]["TXTIPIND"].ToString()) + 1;
                }
                #endregion

                #region InsertTXTIND
                or1.CommandText = "INSERT INTO TXTIND "
            + "SELECT '" + MANDANT + "', 'VKT', '" + TXTISIND + "', '" + SPRACHKZ + " '," + TXTIPIND
                + ", '                              ', ' ', '    ', ' ', ' ', '        ', 0,"
                + "'" + UserID + "', " + date + ", 0, 0, ' ',' ', '         ' FROM DUAL";

                setResult = Connect2Proxy(or1);
                if (POS == "000")
                {
                    dwVKPOS["KTXTIPIND"] = TXTIPIND;
                    or1.CommandText = "UPDATE VKKOPF SET VKKBESTTEXT='F' WHERE VKKAUFKRS='" + KRS + "' AND  VKKAUFLFD='" + LFD + "'";
                    Connect2Proxy(or1);

                    //InsertTXTKON(dwVKPOS, "KTXTIPIND");
                }
                else
                {
                    dwVKPOS["PTXTIPIND"] = TXTIPIND;
                    or1.CommandText = "UPDATE VKPOS SET VKPBESTTEXT='F' WHERE VKPAUFKRS='" + KRS + "' AND  VKPAUFLFD='" + LFD + "' AND VKPAUFPOS='" + POS + "'";
                    Connect2Proxy(or1);
                    //InsertTXTKON(dwVKPOS, "PTXTIPIND");
                }
                #endregion
                setReturn = GetVKTXT(dwVKPOS, type, false);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public void InsertTXTKON(DataRow dwVKPOS, int linestart, int lineend, int lineuser, string user, string type = "KVKTTXT")
        {
            DataSet setResult;
            string text;
            string TXTIPIND;
            string field;
            OracleCommand or1 = OracleDB.CreateCommand();
            string SqlInsert = "";
            string INDTYPE = "";
            try
            {
                if (type == "KVKTTXT")
                {
                    TXTIPIND = dwVKPOS["KTXTIPIND"].ToString();
                }
                else
                {
                    TXTIPIND = dwVKPOS["PTXTIPIND"].ToString();
                }
                for (int TXTKPOS = linestart; TXTKPOS < lineend + 2; TXTKPOS++)
                {
                    text = "";

                    string pos = "";
                    if (TXTKPOS == lineend + 1)
                    {
                        TXTKPOS = lineuser;
                        text = user;
                    }
                    else
                    {
                        pos = Right("0" + TXTKPOS.ToString(), 2);
                        string column = Left(type + pos, 9);
                        text = dwVKPOS[column].ToString();
                    }

                    if (text.Trim().Count() == 0)
                    {
                        text = ".";
                    }
                    if (text == user && TXTKPOS == 0)
                    {
                        break;
                    }
                    text = ConvertGB2312To8859P1(text);
                    text = Left(text + "                                                                                ", 80);
                    or1.CommandText = "SELECT COUNT(*)  AS NUMEXIST FROM TXTKON "
                    + " WHERE TXTKMANDANT='" + MANDANT + "' AND TXTKPIND=" + TXTIPIND + " AND TXTKPOS=" + (TXTKPOS * 10).ToString();
                    setResult = Connect2Proxy(or1);
                    if (setResult.Tables.Count > 0)
                    {
                        int NUMEXIST = System.Convert.ToInt32(setResult.Tables[0].Rows[0]["NUMEXIST"].ToString());
                        if (NUMEXIST > 0)
                        {
                            #region UpdateTXTKON
                            or1.CommandText = "UPDATE TXTKON SET TXTKTEXT='" + text + "'"
                           + " WHERE TXTKMANDANT='" + MANDANT + "' AND TXTKPIND=" + TXTIPIND + " AND TXTKPOS=" + (TXTKPOS * 10).ToString(); ;
                            setResult = Connect2Proxy(or1);
                            #endregion
                        }
                        else
                        {
                            #region InsertTXTKON
                            or1.CommandText = "INSERT INTO TXTKON "
                            + " SELECT 20, '  ', '" + MANDANT + "', " + TXTIPIND + ", " + (TXTKPOS * 10).ToString() + ", 0, '" + text + "' "
                            + " FROM DUAL";
                            setResult = Connect2Proxy(or1);
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void UpdateTXTKON(DataTable tbVKPOS, string userID, string userGroup)
        {
            try
            {
                int linestart = 1;
                int lineend = 1;
                int lineuser = 31;
                foreach (DataRow dwVKPOS in tbVKPOS.Rows)
                {
                    switch (userGroup)
                    {
                        case "EDIT_VK":
                            linestart = 1;
                            lineend = 12;
                            lineuser = 31;
                            InsertTXTKON(dwVKPOS, linestart, lineend, lineuser, userID, "KVKTTXT");
                            return;
                            break;
                        case "EDIT_TE":
                            linestart = 1;
                            lineend = 5;
                            lineuser = 31;
                            break;
                        case "EDIT_TEM":
                            linestart = 6;
                            lineend = 8;
                            lineuser = 32;
                            break;
                        case "EDIT_EK":
                            linestart = 9;
                            lineend = 13;
                            lineuser = 33;
                            break;
                        default:
                            linestart = 1;
                            lineend = 30;
                            lineuser = 0;
                            InsertTXTKON(dwVKPOS, linestart, lineend, lineuser, userID, "KVKTTXT");
                            break;
                    }
                    InsertTXTKON(dwVKPOS, linestart, lineend, lineuser, userID, "PVKTTXT");
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet ListVKPOS(DataRow dwVKKOPF)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            OracleCommand or1;
            string VKPNEUDAT = dwVKKOPF["VKPNEUDAT"].ToString().Trim();
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT VKPAUFKRS,VKPAUFLFD,VKPAUFPOS,VKPPOSTYP,VKPKDBEZ,VKPKDARTNR,VKPKDFARBNR,ROUND(VKPMENGE1*0.01,0) AS VKPMENGE1,VKPMEEH,VKPLIEFTERM"
                + ",'' AS EDIT_VK,'' AS EDIT_TE,''AS EDIT_TEM,'' AS EDIT_EK FROM VKPOS WHERE VKPSA='  ' AND VKPNEUDAT>='" + VKPNEUDAT + "'";

                setLocal = Connect2Proxy(or1);
                if (setLocal.Tables.Count > 0)
                {
                    tableLocal = setLocal.Tables[0];
                    tableLocal.TableName = "LISTVKPOS";
                    DataTable dbTmp = tableLocal.Clone();
                    dbTmp.TableName = "EDIT_VK";
                    set4Return.Merge(dbTmp);
                    dbTmp = tableLocal.Clone();
                    dbTmp.TableName = "EDIT_TE";
                    set4Return.Merge(dbTmp);
                    dbTmp = tableLocal.Clone();
                    dbTmp.TableName = "EDIT_TEM";
                    set4Return.Merge(dbTmp);
                    dbTmp = tableLocal.Clone();
                    dbTmp.TableName = "EDIT_EK";
                    set4Return.Merge(dbTmp);
                    dbTmp.TableName = "EDIT_TD";
                    set4Return.Merge(dbTmp);
                    byte[] b;
                    string value;
                    string sTemp = "";
                    string Column = "";
                    string KDKUNDNA;
                    string User = "";
                    bool flagremoved = false;
                    int maxstep = 0;
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        Column = "VKPKDFARBNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "VKPKDARTNR";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        Column = "VKPKDBEZ";
                        #region
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[Column].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[Column] = value;
                        #endregion
                        flagremoved = false;
                        maxstep = 0;
                        string KRS = dwTemp["VKPAUFKRS"].ToString().Trim();
                        string LFD = dwTemp["VKPAUFLFD"].ToString().Trim();
                        string POS = "000";
                        string VKPAUF = KRS + LFD + POS;
                        string TXTISIND = VKPAUF + "BEST" + "                                             ";
                        #region EDIT_VK
                        or1.CommandText = "SELECT TXTKTEXT FROM TXTIND T "
                        + " LEFT JOIN TXTKON N ON T.TXTIMANDANT=N.TXTKMANDANT  AND TXTIPIND=TXTKPIND AND TXTKPOS='310'"
                        + "WHERE TXTIMANDANT='00' AND TXTITXTART='VKT' AND TXTISIND = '" + TXTISIND + "'";
                        setResult = Connect2Proxy(or1);
                        if (setResult.Tables.Count > 0)
                        {
                            if (setResult.Tables[0].Rows.Count > 0)
                            {
                                User = this.Left(setResult.Tables[0].Rows[0][0].ToString().Trim() + "        ", 8);
                                if (User.Trim() != "")
                                {
                                    dwTemp["EDIT_VK"] = User;
                                    maxstep = 1;
                                }
                            }
                        }

                        POS = dwTemp["VKPAUFPOS"].ToString().Trim();
                        VKPAUF = KRS + LFD + POS;
                        TXTISIND = VKPAUF + "BEST" + "                                             ";
                        or1.CommandText = "SELECT TXTKPOS, TXTKTEXT FROM TXTIND T "
                      + " LEFT JOIN TXTKON N ON T.TXTIMANDANT=N.TXTKMANDANT  AND TXTIPIND=TXTKPIND AND TXTKPOS in ('310','320','330')"
                      + "WHERE TXTIMANDANT='00' AND TXTITXTART='VKT' AND TXTISIND = '" + TXTISIND + "'";
                        setResult = Connect2Proxy(or1);
                        if (setResult.Tables.Count > 0)
                        {
                            foreach (DataRow dwX in setResult.Tables[0].Rows)
                            {
                                User = this.Left(dwX[1].ToString().Trim() + "        ", 8);
                                string UserType = dwX[0].ToString().Trim();
                                if (User.Trim() != "")
                                {
                                    flagremoved = true;
                                    switch (UserType)
                                    {
                                        case "310":
                                            maxstep = 2;
                                            dwTemp["EDIT_TE"] = User;
                                            break;
                                        case "320":
                                            dwTemp["EDIT_TEM"] = User;
                                            maxstep = 3;
                                            break;
                                        case "330":
                                            maxstep = 4;
                                            dwTemp["EDIT_EK"] = User;
                                            break;
                                    }
                                }
                            }
                        }
                        #endregion
                        if (maxstep == 0)
                        {
                            set4Return.Tables["EDIT_TD"].Rows.Add(dwTemp.ItemArray);
                            continue;
                        }
                        if (maxstep == 4)
                        {
                            set4Return.Tables["EDIT_EK"].Rows.Add(dwTemp.ItemArray);
                            continue;
                        }
                        if (maxstep == 3)
                        {
                            set4Return.Tables["EDIT_TEM"].Rows.Add(dwTemp.ItemArray);
                            continue;
                        }
                        if (maxstep == 2)
                        {
                            set4Return.Tables["EDIT_TE"].Rows.Add(dwTemp.ItemArray);
                            continue;
                        }
                        if (maxstep == 1)
                        {
                            set4Return.Tables["EDIT_VK"].Rows.Add(dwTemp.ItemArray);
                            continue;
                        }

                    }
                    set4Return.Merge(setLocal);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet GetData(DataRow dwUI)
        {
            string progress = "查询完成";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataSet setTXTKOPF = new DataSet();
            try
            {
                EventDispatcher.Instance.RaiseStatus("查询开始", StatusEventType.StartProgress);
                setResult = GetVKKOPF(dwUI);
                setReturn.Merge(setResult);
                DataRow dwVKKOPF = dwUI;
                foreach (DataRow dwTemp in setResult.Tables["VKKOPF"].Rows)
                {
                    dwVKKOPF = dwTemp;
                    setReturn.Merge(GetVKPOS(dwTemp));
                }
                DataRow dwVKKPOS = setReturn.Tables["VKPOS"].Clone().NewRow();
                dwVKKPOS["VKPMANDANT"] = dwVKKOPF["VKKMANDANT"];
                dwVKKPOS["VKPAUFKRS"] = dwVKKOPF["VKKAUFKRS"];
                dwVKKPOS["VKPAUFLFD"] = dwVKKOPF["VKKAUFLFD"];
                dwVKKPOS["VKPAUFPOS"] = "000";
                setTXTKOPF = GetVKTXT(dwVKKPOS, "BEST", checkVK07);
                foreach (DataRow dwVKPOS in setReturn.Tables["VKPOS"].Rows)
                {
                    dwVKPOS["KTXTIPIND"] = dwVKKPOS["KTXTIPIND"];
                }
                foreach (DataRow dwTXT in setTXTKOPF.Tables["TXTKON"].Rows)
                {
                    int TXTKPOS = System.Convert.ToInt32(dwTXT["TXTKPOS"].ToString().Trim()) / 10;
                    string pos = Right("0" + TXTKPOS.ToString(), 2);
                    string column = Left("KVKTTXT" + pos, 9);
                    foreach (DataRow dwVKPOS in setReturn.Tables["VKPOS"].Rows)
                    {
                        dwVKPOS[column] = dwTXT["TXTKTEXT"];
                        dwVKPOS["KTXTIPIND"] = dwTXT["TXTIPIND"];
                    }
                }
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}